package com.newtouch.bxzs.policy.service.impl;

import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.newtouch.bxzs.common.base.BaseErrorEnum;
import com.newtouch.bxzs.common.base.BaseException;
import com.newtouch.bxzs.common.base.em.CompanyParameterTypeEnum;
import com.newtouch.bxzs.common.base.em.DistributionTypeEnum;
import com.newtouch.bxzs.common.base.em.PolicyNatureType;
import com.newtouch.bxzs.common.base.em.SystemParamsEnum;
import com.newtouch.bxzs.common.base.util.CooperationCompanyUtils;
import com.newtouch.bxzs.common.base.util.RedisUtils;
import com.newtouch.bxzs.common.base.util.SendHttpRequestUtils;
import com.newtouch.bxzs.common.base.util.UserDetailUtil;
import com.newtouch.bxzs.policy.mapper.PolicyMapper;
import com.newtouch.bxzs.policy.model.bo.PreservationBO;
import com.newtouch.bxzs.policy.model.bo.enterprise.*;
import com.newtouch.bxzs.policy.model.bo.family.PolicyUserListBO;
import com.newtouch.bxzs.policy.model.vo.PolicyInfoPageVO;
import com.newtouch.bxzs.policy.model.vo.PolicyUserListVO;
import com.newtouch.bxzs.policy.model.vo.PreservationProgressInfoVO;
import com.newtouch.bxzs.policy.model.vo.enterprise.*;
import com.newtouch.bxzs.policy.service.EnterprisePolicyService;
import com.newtouch.bxzs.policy.util.QueryCriteriaUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * 企业单管理实现类
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2021/1/7 13:33</td>
 * <td>linhongxi</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author linhongxi
 * @version 1.0.0
 * @since 1.0.0
 */
@Service
public class EnterprisePolicyServiceImpl implements EnterprisePolicyService {

    @Resource
    private PolicyMapper policyMapper;

    @Autowired
    private RedisUtils redisUtils;

    @Autowired
    private CooperationCompanyUtils cooperationCompanyUtils;

    /**
     * 根据查询条件查询企业单列表信息
     * com.newtouch.bxzs.policy.service.PolicyService#getIndividualPolicyList
     * @param enterprisePolicyVO 企业单列表查询条件
     * @return 企业单列表信息
     */
    @Override
    public IPage<EnterprisePolicyBO> getEnterprisePolicyList(EnterprisePolicyVO enterprisePolicyVO) {
        //查询条件--日期验证
        QueryCriteriaUtils.queryValidationByDate(enterprisePolicyVO.getPolicyApplicationDate(),enterprisePolicyVO.getPolicyExpirationDate());
        //查询条件--保单号验证
        QueryCriteriaUtils.queryValidationByNumber(enterprisePolicyVO.getPolicyNumber());
        //查询条件--投保单位名称验证
        QueryCriteriaUtils.queryValidationByCompanyName(enterprisePolicyVO.getPolicyApplicationCompanyName());
        Page<EnterprisePolicyBO> policyPage= new Page<>(enterprisePolicyVO.getCurrentPage(),
                enterprisePolicyVO.getPageSize());
        enterprisePolicyVO.setUserJobNumber(Objects.requireNonNull(UserDetailUtil.getUserDetail()).getUserJobNumber());
        return policyMapper.enterprisePolicyListBO(enterprisePolicyVO,policyPage,PolicyNatureType.ENTERPRISE_POLICY_NATURE_SHORT.getCode(),PolicyNatureType.ENTERPRISE_POLICY_NATURE_LONG.getCode());
    }

    /**
     * 根据保单号查询企业单详情信息
     * com.newtouch.bxzs.policy.service.PolicyService#getIndividualPolicyInfo
     * @param enterprisePolicyInfoVO 企业单详情信息查询条件
     * @return 企业单详情信息
     */
    @Override
    public EnterprisePolicyBO getEnterprisePolicyInfo(EnterprisePolicyInfoVO enterprisePolicyInfoVO) {
        if(StringUtils.isEmpty(enterprisePolicyInfoVO.getPolicyNumber())){
            throw new BaseException(BaseErrorEnum.REQUEST_DATA_NULL.getResultCode(),BaseErrorEnum.REQUEST_DATA_NULL.getResultMsg());
        }
        enterprisePolicyInfoVO.setUserJobNumber(Objects.requireNonNull(UserDetailUtil.getUserDetail()).getUserJobNumber());
        SendHttpRequestUtils<EnterprisePolicyInfoVO> sendHttpRequest = new SendHttpRequestUtils<>();
        if (redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()).equals(DistributionTypeEnum.BANK.getCode())) {
            JSONObject response = sendHttpRequest.sendHttpRequestToJson(enterprisePolicyInfoVO, cooperationCompanyUtils.getCompanyUrl(enterprisePolicyInfoVO.getInsuranceCompanyName(),
            CompanyParameterTypeEnum.ENTERPRISE_POLICY_INFO.getCode()));
            Object data = response.get("data");
            if(!StringUtils.isEmpty(data)){
                return JSONObject.toJavaObject(JSONObject.parseObject(JSONUtil.toJsonStr(data)),EnterprisePolicyBO.class);
            }
        }
        if (redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()).equals(DistributionTypeEnum.INSURANCE.getCode())) {
            String url = redisUtils.get(SystemParamsEnum.ENTERPRISE_POLICY_INFO.getCode());
            return JSON.toJavaObject(sendHttpRequest.sendHttpRequestToJson(enterprisePolicyInfoVO, url),EnterprisePolicyBO.class);
        }
        return null;
    }

    /**
     * 根据保单号获取企业单保全列表
     *
     * @param policyInfoPageVO 企业单详情--保全信息查询条件
     *
     * @return 企业单详情--保全信息
     */
    @Override
    public List<PreservationBO> getEnterprisePolicyPreservation(PolicyInfoPageVO policyInfoPageVO){
        if(StringUtils.isEmpty(policyInfoPageVO.getPolicyNumber())){
            throw new BaseException(BaseErrorEnum.REQUEST_DATA_NULL.getResultCode(),BaseErrorEnum.REQUEST_DATA_NULL.getResultMsg());
        }
        policyInfoPageVO.setUserJobNumber(Objects.requireNonNull(UserDetailUtil.getUserDetail()).getUserJobNumber());
        //调用外部接口获取企业单详情中的保全信息
        SendHttpRequestUtils<PolicyInfoPageVO> sendHttpRequest = new SendHttpRequestUtils<>();
        if (redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()).equals(DistributionTypeEnum.BANK.getCode())) {
            JSONObject response = sendHttpRequest.sendHttpRequestToJson(policyInfoPageVO, cooperationCompanyUtils.getCompanyUrl(policyInfoPageVO.getInsuranceCompanyName(),
                    CompanyParameterTypeEnum.ENTERPRISE_POLICY_INFO_PRESERVATION.getCode()));
            Object data = response.get("data");
            if(data != null){
                String result = JSONUtil.toJsonStr(data);
                if(!StringUtils.isEmpty(data)){
                    return JSON.parseArray(result,PreservationBO.class);
                }
            }
        }
        if (redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()).equals(DistributionTypeEnum.INSURANCE.getCode())) {
            String url = redisUtils.get(SystemParamsEnum.ENTERPRISE_POLICY_INFO_PRESERVATION.getCode());
            return JSONObject.parseArray(sendHttpRequest.sendHttpRequestToArray(policyInfoPageVO,url).toJSONString(),PreservationBO.class);
        }
        return null;
    }

    /**
     * 根据保单号获取理赔列表
     *
     * @param policyInfoPageVO 企业单详情--理赔信息查询条件
     *
     * @return 企业单详情--理赔信息
     */
    @Override
    public List<EnterpriseClaimsBO> getEnterprisePolicyClaims(PolicyInfoPageVO policyInfoPageVO){
        if(StringUtils.isEmpty(policyInfoPageVO.getPolicyNumber())){
            throw new BaseException(BaseErrorEnum.REQUEST_DATA_NULL.getResultCode(),BaseErrorEnum.REQUEST_DATA_NULL.getResultMsg());
        }
        policyInfoPageVO.setUserJobNumber(Objects.requireNonNull(UserDetailUtil.getUserDetail()).getUserJobNumber());
        //调用外部接口获取企业单详情中的理赔信息
        SendHttpRequestUtils<PolicyInfoPageVO> sendHttpRequest = new SendHttpRequestUtils<>();
        if (redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()).equals(DistributionTypeEnum.BANK.getCode())) {
            JSONObject response =  sendHttpRequest.sendHttpRequestToJson(policyInfoPageVO, cooperationCompanyUtils.getCompanyUrl(policyInfoPageVO.getInsuranceCompanyName(),
                    CompanyParameterTypeEnum.ENTERPRISE_POLICY_INFO_CLAIMS.getCode()));
            Object data = response.get("data");
            if(data != null){
                String result = JSONUtil.toJsonStr(data);
                if(!StringUtils.isEmpty(data)){
                    return JSON.parseArray(result,EnterpriseClaimsBO.class);
                }
            }
        }
        if (redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()).equals(DistributionTypeEnum.INSURANCE.getCode())) {
            String url = redisUtils.get(SystemParamsEnum.ENTERPRISE_POLICY_INFO_CLAIMS.getCode());
            return JSONObject.parseArray(sendHttpRequest.sendHttpRequestToArray(policyInfoPageVO, url).toJSONString(),EnterpriseClaimsBO.class);
        }
        return null;
    }
    /**
     * 根据保单号获取企业单人员清单列表
     *
     * @param policyUserListVO 企业单详情--人员清单信息查询条件
     *
     * @return 企业单详情--人员清单信息
     */
    @Override
    public List<PolicyUserListBO> getEnterprisePolicyUserList(PolicyUserListVO policyUserListVO){
        if(StringUtils.isEmpty(policyUserListVO.getPolicyNumber())){
            throw new BaseException(BaseErrorEnum.REQUEST_DATA_NULL.getResultCode(),BaseErrorEnum.REQUEST_DATA_NULL.getResultMsg());
        }
        policyUserListVO.setUserJobNumber(Objects.requireNonNull(UserDetailUtil.getUserDetail()).getUserJobNumber());
        //调用外部接口查询企业单详情人员清单列表
        SendHttpRequestUtils<PolicyUserListVO> sendHttpRequest = new SendHttpRequestUtils<>();
        if (redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()).equals(DistributionTypeEnum.BANK.getCode())) {
            JSONObject response = sendHttpRequest.sendHttpRequestToJson(policyUserListVO, cooperationCompanyUtils.getCompanyUrl(policyUserListVO.getInsuranceCompanyName(),
            CompanyParameterTypeEnum.ENTERPRISE_POLICY_INFO_USER.getCode()));
            Object data = response.get("data");
            if(data != null){
                String result = JSONUtil.toJsonStr(data);
                if(!StringUtils.isEmpty(data)){
                    return JSON.parseArray(result,PolicyUserListBO.class);
                }
            }
        }
        if (redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()).equals(DistributionTypeEnum.INSURANCE.getCode())) {
            String url = redisUtils.get(SystemParamsEnum.ENTERPRISE_POLICY_INFO_USER.getCode());
            return JSONObject.parseArray(sendHttpRequest.sendHttpRequestToArray(policyUserListVO, url).toJSONString(),PolicyUserListBO.class);
        }
        return null;
    }
    /**
     * 根据查询条件获取新契约进度列表
     *
     * @param enterprisePolicyNewContractVO 企业单新契约进度列表信息查询条件
     *
     * @return 企业单新契约进度列表信息
     */
    @Override
    public List<EnterprisePolicyNewContractBO> getNewContractListByEnterprisePolicy(EnterprisePolicyNewContractVO enterprisePolicyNewContractVO){
        //查询条件--日期验证
        QueryCriteriaUtils.queryValidationByDate(enterprisePolicyNewContractVO.getPolicyApplicationDate(),enterprisePolicyNewContractVO.getPolicyExpirationDate());
        //查询条件--投保单号验证
        QueryCriteriaUtils.queryValidationByNumber(enterprisePolicyNewContractVO.getPolicyApplicationNumber());
        //查询条件--投保单位名称验证
        QueryCriteriaUtils.queryValidationByCompanyName(enterprisePolicyNewContractVO.getPolicyApplicationCompanyName());
        //调用外部接口获取新契约保单信息
        SendHttpRequestUtils<EnterprisePolicyNewContractVO> sendHttpRequest = new SendHttpRequestUtils<>();
        if (redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()).equals(DistributionTypeEnum.BANK.getCode())) {
            JSONObject response = sendHttpRequest.sendHttpRequestToJson(enterprisePolicyNewContractVO, cooperationCompanyUtils.getCompanyUrl(enterprisePolicyNewContractVO.getInsuranceCompanyName(),
            CompanyParameterTypeEnum.ENTERPRISE_POLICY_NEW_CONTRACT.getCode()));
            Object data = response.get("data");
            if(data != null){
                String result = JSONUtil.toJsonStr(data);
                if(!StringUtils.isEmpty(data)){
                    return JSON.parseArray(result,EnterprisePolicyNewContractBO.class);
                }
            }
        }
        if (redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()).equals(DistributionTypeEnum.INSURANCE.getCode())) {
            String url = redisUtils.get(SystemParamsEnum.ENTERPRISE_POLICY_NEW_CONTRACT.getCode());
            return   JSONArray.parseArray(sendHttpRequest.sendHttpRequestToArray(enterprisePolicyNewContractVO, url).toJSONString(),EnterprisePolicyNewContractBO.class);
        }
        return null;
    }

    /**
     * 根据保单号获取新契约进度详情
     *
     * @param enterprisePolicyNewContractInfoVO 企业单新契约进度详情信息查询条件
     *
     * @return 企业单新契约进度详情信息
     */
    @Override
    public EnterprisePolicyNewContractBO getNewContractInfoByEnterprisePolicy(EnterprisePolicyNewContractInfoVO enterprisePolicyNewContractInfoVO){
        if(StringUtils.isEmpty(enterprisePolicyNewContractInfoVO.getPolicyApplicationNumber())){
            throw new BaseException(BaseErrorEnum.REQUEST_DATA_NULL.getResultCode(),BaseErrorEnum.REQUEST_DATA_NULL.getResultMsg());
        }
        enterprisePolicyNewContractInfoVO.setUserJobNumber(Objects.requireNonNull(UserDetailUtil.getUserDetail()).getUserJobNumber());
        //调用外部接口获取企业单新契约进度详情信息
        SendHttpRequestUtils<EnterprisePolicyNewContractInfoVO> sendHttpRequest = new SendHttpRequestUtils<>();
        if (redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()).equals(DistributionTypeEnum.BANK.getCode())) {
            JSONObject response = sendHttpRequest.sendHttpRequestToJson(enterprisePolicyNewContractInfoVO, cooperationCompanyUtils.getCompanyUrl(enterprisePolicyNewContractInfoVO.getInsuranceCompanyName(),
            CompanyParameterTypeEnum.ENTERPRISE_POLICY_NEW_CONTRACT_INFO.getCode()));
            Object data = response.get("data");
            if(!StringUtils.isEmpty(data)){
                return JSONObject.toJavaObject(JSONObject.parseObject(JSONUtil.toJsonStr(data)),EnterprisePolicyNewContractBO.class);
            }
        }
        if (redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()).equals(DistributionTypeEnum.INSURANCE.getCode())) {
            String url = redisUtils.get(SystemParamsEnum.ENTERPRISE_POLICY_NEW_CONTRACT_INFO.getCode());
            return JSON.toJavaObject(sendHttpRequest.sendHttpRequestToJson(enterprisePolicyNewContractInfoVO, url),EnterprisePolicyNewContractBO.class);
        }
        return null;
    }

    /**
     * 根据投保单号获取企业单新契约详情人员清单列表
     *
     * @param enterprisePolicyNewContractUserListVO 企业单新契约进度详情--人员清单信息查询条件
     * @return 企业单新契约进度详情--人员清单信息
     */
    @Override
    public List<PolicyUserListBO> getNewContractUserListByEnterprisePolicy(EnterprisePolicyNewContractUserListVO enterprisePolicyNewContractUserListVO ){
        if(StringUtils.isEmpty(enterprisePolicyNewContractUserListVO.getPolicyApplicationNumber())){
            throw new BaseException(BaseErrorEnum.REQUEST_DATA_NULL.getResultCode(),BaseErrorEnum.REQUEST_DATA_NULL.getResultMsg());
        }
        enterprisePolicyNewContractUserListVO.setUserJobNumber(Objects.requireNonNull(UserDetailUtil.getUserDetail()).getUserJobNumber());
        SendHttpRequestUtils<EnterprisePolicyNewContractUserListVO> sendHttpRequest = new SendHttpRequestUtils<>();
        if (redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()).equals(DistributionTypeEnum.BANK.getCode())) {
            JSONObject response = sendHttpRequest.sendHttpRequestToJson(enterprisePolicyNewContractUserListVO, cooperationCompanyUtils.getCompanyUrl(enterprisePolicyNewContractUserListVO.getInsuranceCompanyName(),
            CompanyParameterTypeEnum.ENTERPRISE_POLICY_NEW_CONTRACT_INFO_USER.getCode()));
            Object data = response.get("data");
            if(data != null){
                String result = JSONUtil.toJsonStr(data);
                if(!StringUtils.isEmpty(data)){
                    return JSON.parseArray(result,PolicyUserListBO.class);
                }
            }
        }
        if (redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()).equals(DistributionTypeEnum.INSURANCE.getCode())) {
            String url = redisUtils.get(SystemParamsEnum.ENTERPRISE_POLICY_NEW_CONTRACT_INFO_USER.getCode());
            return JSONObject.parseArray(sendHttpRequest.sendHttpRequestToArray(enterprisePolicyNewContractUserListVO, url).toJSONString(),PolicyUserListBO.class);
        }
        return null;
    }

    /**
     * 根据查询条件获取保全进度列表
     *
     * @param enterprisePreservationVO 企业单保全进度列表信息查询条件
     *
     * @return 企业单保全进度列表信息
     */
    @Override
    public List<EnterprisePreservationProgressInfoBO> getPreservationListByEnterPrisePolicy(EnterprisePreservationVO enterprisePreservationVO){
        //查询条件--保单号验证
        QueryCriteriaUtils.queryValidationByNumber(enterprisePreservationVO.getPolicyNumber());
        //查询条件--保全受理号验证
        QueryCriteriaUtils.queryValidationByNumber(enterprisePreservationVO.getPreservationAcceptanceNumber());
        //查询条件--投保单位名称验证
        QueryCriteriaUtils.queryValidationByCompanyName(enterprisePreservationVO.getPolicyApplicationCompanyName());
        //获取用户工号
        enterprisePreservationVO.setUserJobNumber(Objects.requireNonNull(UserDetailUtil.getUserDetail()).getUserJobNumber());
        //调用外部接口获取保全进度列表信息
        SendHttpRequestUtils<EnterprisePreservationVO> sendHttpRequest = new SendHttpRequestUtils<>();
        if (redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()).equals(DistributionTypeEnum.BANK.getCode())) {
           JSONObject response = sendHttpRequest.sendHttpRequestToJson(enterprisePreservationVO,cooperationCompanyUtils.getCompanyUrl(enterprisePreservationVO.getInsuranceCompanyName(),
            CompanyParameterTypeEnum.ENTERPRISE_POLICY_PRESERVATION.getCode()));
            Object data = response.get("data");
            if(data != null){
                String result = JSONUtil.toJsonStr(data);
                if(!StringUtils.isEmpty(data)){
                    return JSON.parseArray(result,EnterprisePreservationProgressInfoBO.class);
                }
            }
        }
        if (redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()).equals(DistributionTypeEnum.INSURANCE.getCode())) {
            String url = redisUtils.get(SystemParamsEnum.FAMILY_POLICY_PRESERVATION.getCode());
            return JSONObject.parseArray(sendHttpRequest.sendHttpRequestToArray(enterprisePreservationVO, url).toJSONString(),EnterprisePreservationProgressInfoBO.class);
        }
        return null;
    }
    /**
     * 根据保单号获取保全进度详情
     *
     * @param preservationProgressInfoVO 企业单保全进度详情信息查询条件
     *
     * @return 企业单保全进度详情信息
     */
    @Override
    public EnterprisePreservationProgressInfoBO getPreservationInfoByEnterPrisePolicy(PreservationProgressInfoVO preservationProgressInfoVO){
        if(StringUtils.isEmpty(preservationProgressInfoVO.getPreservationAcceptanceNumber())){
            throw new BaseException(BaseErrorEnum.REQUEST_DATA_NULL.getResultCode(),BaseErrorEnum.REQUEST_DATA_NULL.getResultMsg());
        }
        //获取用户工号
        preservationProgressInfoVO.setUserJobNumber(Objects.requireNonNull(UserDetailUtil.getUserDetail()).getUserJobNumber());
        //调用外部接口获取家庭单保全进度详情信息
        SendHttpRequestUtils<PreservationProgressInfoVO> sendHttpRequest = new SendHttpRequestUtils<>();
        if (redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()).equals(DistributionTypeEnum.BANK.getCode())) {
            JSONObject response = sendHttpRequest.sendHttpRequestToJson(preservationProgressInfoVO, cooperationCompanyUtils.getCompanyUrl(preservationProgressInfoVO.getInsuranceCompanyName(),
                    CompanyParameterTypeEnum.ENTERPRISE_POLICY_PRESERVATION_INFO.getCode()));
            Object data = response.get("data");
            if(!StringUtils.isEmpty(data)){
                return JSONObject.toJavaObject(JSONObject.parseObject(JSONUtil.toJsonStr(data)),
                        EnterprisePreservationProgressInfoBO.class);
            }
        }
        if (redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()).equals(DistributionTypeEnum.INSURANCE.getCode())) {
            String url = redisUtils.get(CompanyParameterTypeEnum.FAMILY_POLICY_PRESERVATION_INFO.getCode());
            return JSON.toJavaObject(sendHttpRequest.sendHttpRequestToJson(preservationProgressInfoVO, url),EnterprisePreservationProgressInfoBO.class);
        }
        return  null;
    }

    /**
     * 根据查询条件获取理赔进度列表
     *
     * @param enterpriseClaimsVO 企业单理赔进度列表信息查询条件
     *
     * @return 企业单理赔进度列表信息
     */
    @Override
    public List<EnterpriseClaimsProgressBO> getClaimsProgressListByEnterprisePolicy(EnterpriseClaimsVO enterpriseClaimsVO){
        //查询条件--日期验证
        QueryCriteriaUtils.queryValidationByDate(enterpriseClaimsVO.getApplicationStartDate(),enterpriseClaimsVO.getApplicationDeadline());
        //查询条件--保单号验证
        QueryCriteriaUtils.queryValidationByNumber(enterpriseClaimsVO.getPolicyNumber());
        //查询条件--批次号验证
        QueryCriteriaUtils.queryValidationByNumber(enterpriseClaimsVO.getBatchNumber());
        //查询条件--投保人名称验证
        QueryCriteriaUtils.queryValidationByName(enterpriseClaimsVO.getPolicyHolderName(),null);
        //获取用户工号
        enterpriseClaimsVO.setUserJobNumber(Objects.requireNonNull(UserDetailUtil.getUserDetail()).getUserJobNumber());
        //调用外部接口获取理赔进度信息
        SendHttpRequestUtils<EnterpriseClaimsVO> sendHttpRequest = new SendHttpRequestUtils<>();
        if (redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()).equals(DistributionTypeEnum.BANK.getCode())) {
            JSONObject response = sendHttpRequest.sendHttpRequestToJson(enterpriseClaimsVO, cooperationCompanyUtils.getCompanyUrl(enterpriseClaimsVO.getInsuranceCompanyName(),
            CompanyParameterTypeEnum.ENTERPRISE_POLICY_CLAIMS.getCode()));
            Object data = response.get("data");
            if(data != null){
                String result = JSONUtil.toJsonStr(data);
                if(!StringUtils.isEmpty(data)){
                    return JSON.parseArray(result,EnterpriseClaimsProgressBO.class);
                }
            }
        }
        if (redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()).equals(DistributionTypeEnum.INSURANCE.getCode())) {
            String url = redisUtils.get(CompanyParameterTypeEnum.ENTERPRISE_POLICY_CLAIMS.getCode());
            return JSONObject.parseArray(sendHttpRequest.sendHttpRequestToArray(enterpriseClaimsVO, url).toJSONString(),EnterpriseClaimsProgressBO.class);
        }
        return null;
    }

    /**
     * 根据保单号获取理赔进度--个人列表
     *
     * @param policyUserListVO 企业单理赔进度--个人列表信息查询条件
     *
     * @return 企业单保全进度--个人列表信息
     */
    @Override
    public List<EnterpriseClaimsProgressBO> getClaimsProgressUserListByEnterprisePolicy(PolicyUserListVO policyUserListVO){
        if(StringUtils.isEmpty(policyUserListVO.getPolicyNumber())){
            throw new BaseException(BaseErrorEnum.REQUEST_DATA_NULL.getResultCode(),BaseErrorEnum.REQUEST_DATA_NULL.getResultMsg());
        }
        //获取用户工号
        policyUserListVO.setUserJobNumber(Objects.requireNonNull(UserDetailUtil.getUserDetail()).getUserJobNumber());
        //调用外部接口获取理赔进度--个人列表
        SendHttpRequestUtils<PolicyInfoPageVO> sendHttpRequest = new SendHttpRequestUtils<>();
        if (redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()).equals(DistributionTypeEnum.BANK.getCode())) {
            JSONObject response = sendHttpRequest.sendHttpRequestToJson(policyUserListVO, cooperationCompanyUtils.getCompanyUrl(policyUserListVO.getInsuranceCompanyName(),
            CompanyParameterTypeEnum.ENTERPRISE_POLICY_CLAIMS_QUERY.getCode()));
            Object data = response.get("data");
            if(data != null){
                String result = JSONUtil.toJsonStr(data);
                if(!StringUtils.isEmpty(data)){
                    return JSON.parseArray(result,EnterpriseClaimsProgressBO.class);
                }
            }
        }
        if (redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()).equals(DistributionTypeEnum.INSURANCE.getCode())) {
            String url = redisUtils.get(CompanyParameterTypeEnum.ENTERPRISE_POLICY_CLAIMS_QUERY.getCode());
            return JSONObject.parseArray(sendHttpRequest.sendHttpRequestToArray(policyUserListVO, url).toJSONString(),EnterpriseClaimsProgressBO.class);
        }
        return null;
    }

    /**
     * 根据保单号获取理赔进度--批次列表
     *
     * @param policyInfoPageVO 企业单理赔进度--批次列表信息查询条件
     *
     * @return 企业单理赔进度--批次列表信息
     */
    @Override
    public List<EnterpriseClaimsProgressBO> getClaimsProgressBatchListByEnterprisePolicy(PolicyInfoPageVO policyInfoPageVO){
        if(StringUtils.isEmpty(policyInfoPageVO.getPolicyNumber())){
            throw new BaseException(BaseErrorEnum.REQUEST_DATA_NULL.getResultCode(),BaseErrorEnum.REQUEST_DATA_NULL.getResultMsg());
        }
        //获取用户工号
        policyInfoPageVO.setUserJobNumber(Objects.requireNonNull(UserDetailUtil.getUserDetail()).getUserJobNumber());
        //调用外部接口获取理赔进度--批次列表
        SendHttpRequestUtils<PolicyInfoPageVO> sendHttpRequest = new SendHttpRequestUtils<>();
        if (redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()).equals(DistributionTypeEnum.BANK.getCode())) {
            JSONObject response = sendHttpRequest.sendHttpRequestToJson(policyInfoPageVO, cooperationCompanyUtils.getCompanyUrl(policyInfoPageVO.getInsuranceCompanyName(),
            CompanyParameterTypeEnum.ENTERPRISE_POLICY_CLAIMS_BATCH.getCode()));
            Object data = response.get("data");
            if(data != null){
                String result = JSONUtil.toJsonStr(data);
                if(!StringUtils.isEmpty(data)){
                    return JSON.parseArray(result,EnterpriseClaimsProgressBO.class);
                }
            }
        }
        if (redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()).equals(DistributionTypeEnum.INSURANCE.getCode())) {
            String url = redisUtils.get(CompanyParameterTypeEnum.ENTERPRISE_POLICY_CLAIMS_BATCH.getCode());
            return JSONObject.parseArray(sendHttpRequest.sendHttpRequestToArray(policyInfoPageVO, url).toJSONString(),EnterpriseClaimsProgressBO.class);
        }
        return null;
    }
    /**
     * 根据查询条件获取满期保单列表
     *
     * @param enterpriseExpirationPolicyVO 企业单满期列表信息查询条件
     *
     * @return 企业单满期列表信息
     */
    @Override
    public List<EnterpriseExpirationPolicyBO> getExpirationPolicyListByEnterprisePolicy(EnterpriseExpirationPolicyVO enterpriseExpirationPolicyVO){
        //查询条件--保单号验证
        QueryCriteriaUtils.queryValidationByNumber(enterpriseExpirationPolicyVO.getPolicyNumber());
        //查询条件--投保公司名称验证
        QueryCriteriaUtils.queryValidationByCompanyName(enterpriseExpirationPolicyVO.getPolicyApplicationCompanyName());
        //获取用户工号
        enterpriseExpirationPolicyVO.setUserJobNumber(Objects.requireNonNull(UserDetailUtil.getUserDetail()).getUserJobNumber());
        //调用外部接口获取满期保单数据
        SendHttpRequestUtils<EnterpriseExpirationPolicyVO> sendHttpRequest = new SendHttpRequestUtils<>();
        if (redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()).equals(DistributionTypeEnum.BANK.getCode())) {
            JSONObject response = sendHttpRequest.sendHttpRequestToJson(enterpriseExpirationPolicyVO, cooperationCompanyUtils.getCompanyUrl(enterpriseExpirationPolicyVO.getInsuranceCompanyName(),
            CompanyParameterTypeEnum.ENTERPRISE_POLICY_EXPIRATION.getCode()));
            Object data = response.get("data");
            if(data != null){
                String result = JSONUtil.toJsonStr(data);
                if(!StringUtils.isEmpty(data)){
                    return JSON.parseArray(result,EnterpriseExpirationPolicyBO.class);
                }
            }
        }
        if (redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()).equals(DistributionTypeEnum.INSURANCE.getCode())) {
            String url = redisUtils.get(CompanyParameterTypeEnum.ENTERPRISE_POLICY_EXPIRATION.getCode());
            return  JSONObject.parseArray(sendHttpRequest.sendHttpRequestToArray(enterpriseExpirationPolicyVO, url).toJSONString(),EnterpriseExpirationPolicyBO.class);
        }
        return null;
    }

    /**
     * 根据查询条件获取续期保单列表
     *
     * @param enterpriseRenewalPolicyVO 企业单续期列表信息查询条件
     *
     * @return 企业单续期列表信息
     */
    @Override
    public List<EnterpriseRenewalPolicyBO> getRenewalPolicyListByEnterPrisePolicy(EnterpriseRenewalPolicyVO enterpriseRenewalPolicyVO){
        //查询条件--保单号验证
        QueryCriteriaUtils.queryValidationByNumber(enterpriseRenewalPolicyVO.getPolicyNumber());
        //查询条件--投保公司名称验证
        QueryCriteriaUtils.queryValidationByCompanyName(enterpriseRenewalPolicyVO.getPolicyApplicationCompanyName());
        //获取用户工号
        enterpriseRenewalPolicyVO.setUserJobNumber(Objects.requireNonNull(UserDetailUtil.getUserDetail()).getUserJobNumber());
        //调用外部接口查询续期保单列表
        SendHttpRequestUtils<EnterpriseRenewalPolicyVO> sendHttpRequest = new SendHttpRequestUtils<>();
        if (redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()).equals(DistributionTypeEnum.BANK.getCode())) {
            JSONObject response = sendHttpRequest.sendHttpRequestToJson(enterpriseRenewalPolicyVO, cooperationCompanyUtils.getCompanyUrl(enterpriseRenewalPolicyVO.getInsuranceCompanyName(),
            CompanyParameterTypeEnum.ENTERPRISE_POLICY_RENEWAL.getCode()));
            Object data = response.get("data");
            if(data != null){
                String result = JSONUtil.toJsonStr(data);
                if(!StringUtils.isEmpty(data)){
                    return JSON.parseArray(result,EnterpriseRenewalPolicyBO.class);
                }
            }
        }
        if (redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()).equals(DistributionTypeEnum.INSURANCE.getCode())) {
            String url = redisUtils.get(CompanyParameterTypeEnum.ENTERPRISE_POLICY_RENEWAL.getCode());
            return JSONObject.parseArray(sendHttpRequest.sendHttpRequestToArray(enterpriseRenewalPolicyVO, url).toJSONString(),EnterpriseRenewalPolicyBO.class);
        }
        return  null;
    }

}
